package org.jivesoftware.smackx.workgroup.packet;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;

public class AgentWorkgroups extends IQ
{
  private String agentJID;
  private List<String> workgroups;

  public AgentWorkgroups(String paramString)
  {
    this.agentJID = paramString;
    this.workgroups = new ArrayList();
  }

  public AgentWorkgroups(String paramString, List<String> paramList)
  {
    this.agentJID = paramString;
    this.workgroups = paramList;
  }

  public String getAgentJID()
  {
    return this.agentJID;
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<workgroups xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(this.agentJID).append("\">");
    Iterator localIterator = this.workgroups.iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        localStringBuilder.append("</workgroups>");
        return localStringBuilder.toString();
      }
      String str = (String)localIterator.next();
      localStringBuilder.append("<workgroup jid=\"" + str + "\"/>");
    }
  }

  public List<String> getWorkgroups()
  {
    return Collections.unmodifiableList(this.workgroups);
  }

  public static class Provider
  implements IQProvider
  {
    public IQ parseIQ(XmlPullParser paramXmlPullParser)
      throws Exception
    {
      String str = paramXmlPullParser.getAttributeValue("", "jid");
      ArrayList localArrayList = new ArrayList();
      int i = 0;
      while (true)
      {
        int j;
        label85: 
        do
          while (true)
          {
            do
            {
              if (i != 0)
                return new AgentWorkgroups(str, localArrayList);
              j = paramXmlPullParser.next();
              if (j != 2)
                break label85;
            }
            while (!(paramXmlPullParser.getName().equals("workgroup")));
            localArrayList.add(paramXmlPullParser.getAttributeValue("", "jid"));
          }
        while ((j != 3) || (!(paramXmlPullParser.getName().equals("workgroups"))));
        i = 1;
      }
    }
  }
}